<?php

/**
 * 规格属性
 */

namespace app\shop\api;

class SpecApi extends \dux\kernel\Api {

    public function getList() {
        $classId = request('get', 'class_id', 0, 'intval');
        $app = request('get', 'app', '', 'html_clear');
        if(empty($classId)) {
            $this->error('栏目未指定！');
        }
        if(empty($app)) {
            $this->error('应用未指定！');
        }
        $list = target($app.'/'.$app.'Class')->loadCrumbList($classId);
        $groupId = [];
        foreach ($list as $vo) {
            if($vo['spec_group_id']) {
                $groupId = $vo['spec_group_id'];
                break;
            }
        }
        if(empty($groupId)) {
            $this->success([]);
        }
        $info = target('shop/ShopSpecGroup')->getInfo($groupId);
        if(empty($info['spec_ids'])) {
            $this->success([]);
        }
        $specList = target('shop/ShopSpec')->loadList([
            '_sql' => 'spec_id in ('.$info['spec_ids'].')'
        ]);
        $this->success($specList);
    }

}